/*
 * MainServer.java
 *
 * Created on May 2, 2007, 11:45 PM
 *
 *
 * Copyright (c) 2008 Golden T Studios.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package test.chat;

// JFC
import java.io.IOException;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

import com.golden.gamedev.engine.network.tcp.TCPServer;

/**
 * 
 * @author Paulus Tuerah
 */
public class MainServer {
	
	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch (Exception ex) {
		}
		
		// the port to be used
		String port = JOptionPane.showInputDialog("Server Port :", "11137");
		if (port == null) {
			System.exit(0);
		}
		
		int portNumber = 0;
		
		try {
			portNumber = Integer.parseInt(port);
		}
		catch (NumberFormatException ex) {
			ex.printStackTrace();
			System.exit(-1);
		}
		
		// create the server
		TCPServer server = null;
		try {
			server = new TCPServer(portNumber);
			// server.setMaxClients(2);
			
		}
		catch (IOException ex) {
			ex.printStackTrace();
			
			JOptionPane.showMessageDialog(null, "Connection Failed.\n"
			        + "Caused by:\n" + ex.getMessage(), "Connection Failed",
			        JOptionPane.ERROR_MESSAGE);
			
			System.exit(-1);
		}
		
		// show the ui
		new ServerGUI(server).setVisible(true);
	}
	
}
